package com.carcenter.store.controller;

import com.carcenter.common.constant.redis.RedisConstant;
import com.carcenter.common.result.Result;
import com.carcenter.store.entity.StoreChina;
import com.carcenter.store.service.IStoreChinaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author car
 * @since 2025-07-16
 */
@RestController
@RequestMapping("/store-china")
public class StoreChinaController {

    @Autowired
    IStoreChinaService storeChinaService;
    @Autowired
    RedisTemplate redisTemplate;

    @GetMapping("/getProvinces")
    public Result<?> getProvinces() {
        List<StoreChina> provinces = storeChinaService.getAddress(0, RedisConstant.PROVINCES);
        return Result.ok(provinces);
    }

    @GetMapping("/getCities/{provincePid}")
    public Result<?> getCities(@PathVariable Integer provincePid) {
        List<StoreChina> cities = storeChinaService.getAddress(provincePid, RedisConstant.CITIES+":"+provincePid);
        return Result.ok(cities);
    }

    @GetMapping("/getAreas/{cityPid}")
    public Result<?> getAreas(@PathVariable Integer cityPid) {
        List<StoreChina> areas = storeChinaService.getAddress(cityPid, RedisConstant.AREAS+":"+cityPid);
        return Result.ok(areas);
    }


}
